package com.tiancheng.trade.settlement.vo.settlement.export;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tiancheng.trade.settlement.enums.SubOrderStatusEnum;
import com.tiancheng.trade.settlement.util.AmountUtil;
import com.tiancheng.trade.settlement.util.ObjectConvertUtil;
import com.tiancheng.trade.settlement.vo.settlement.admin.res.SettleDetailResVo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Getter
@Setter
@ToString
public class SettleByMerchantDetailExportVo {
    /**
     * 下单时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderCreateDt;
    /**
     * 子订单号
     *
     * @mbg.generated 2021-03-26 14:29:14
     */
    private String subOrderId;

    /**
     * 支付流水号
     *
     * @mbg.generated 2021-03-26 14:29:14
     */
    private String flowId;

    /**
     * 商户名称（中台）
     *
     * @mbg.generated 2021-03-26 14:29:49
     */
    private String merchantName;
    /**
     * 应收金额
     */
    private BigDecimal subOrderAmountBD;
    /**
     * 支付金额
     */
    private BigDecimal payAmountBD;
    /**
     * 优惠总金额
     */
    private BigDecimal discountBD;
    /**
     * 退款金额
     */
    private BigDecimal refundAmountBD;
    /**
     * 清出金额
     */
    private BigDecimal clearAmountBD;
    /**
     * 子订单状态-描述
     */
    private String subOrderStatusStr;
    /**
     * 核销时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime verificationTime;
    /**
     * 差异备注
     *
     * @mbg.generated 2021-03-26 14:29:14
     */
    private String exceptionDesc;
    /**
     * 清分规则编码
     *
     * @mbg.generated 2021-03-26 14:29:14
     */
    private String clearRuleCode;

    public static SettleByMerchantDetailExportVo build(SettleDetailResVo s){
        SettleByMerchantDetailExportVo entity = ObjectConvertUtil.convert(s, SettleByMerchantDetailExportVo.class).get();
        entity.setSubOrderAmountBD(AmountUtil.getYUAN(Math.toIntExact(s.getSubOrderAmount())));
        entity.setPayAmountBD(AmountUtil.getYUAN(Math.toIntExact(s.getPayAmount())));
        entity.setDiscountBD(AmountUtil.getYUAN(Math.toIntExact(s.getDiscount())));
        entity.setRefundAmountBD(AmountUtil.getYUAN(Math.toIntExact(s.getRefundAmount())));
        entity.setClearAmountBD(AmountUtil.getYUAN(Math.toIntExact(s.getClearAmount())));
        entity.setSubOrderStatusStr(SubOrderStatusEnum.getDesc(s.getSubOrderStatus()));
        return entity;
    }
}
